/*
 * BasicEditorStateManager.java
 *
 * Created on October 30, 2007, 8:41 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jia.core.state;

import jia.core.EventProcessor;
import jia.core.GameStateManager;
import jia.core.UiManager;
import jia.core.characters.GameCharacter;
import jia.core.processors.BasicEventProcessor;
import jia.game.GenericFlags;
import org.apache.log4j.Logger;

/**
 *
 * @author gryffonx
 */
public class BasicEditorStateManager implements GameStateManager{
    private static final Logger log = Logger.getLogger(BasicEditorStateManager.class);
    private EventProcessor eventProcessor;
    private UiManager uiManager;
    private PlayerState playerState;
    
    /** Creates a new instance of BasicEditorStateManager */
    public BasicEditorStateManager() {
        playerState = new BasicPlayerState();
        eventProcessor = new BasicEventProcessor();
    }
    
    /**
     * Give the GameStateManager a hook into the EventProcessor
     * @see net.sf.jia.core.GameStateManager#registerEventProcessor(net.sf.jia.core.EventProcessor)
     */
    public void registerEventProcessor(EventProcessor ep){
        this.eventProcessor = ep;
    }
    
    /**
     * Give the GameStateManager a hook into the UiManager
     * @see net.sf.jia.core.GameStateManager#registerUiManager(net.sf.jia.core.UiManager)
     */
    public void registerUiManager(UiManager ui){
        ui.registerGameState(this);
        uiManager = ui;
    }
    
    /**
     * Returns the UiManager registered with this GameStateManager
     * @see net.sf.jia.core.GameStateManager#getUiManager()
     */
    public UiManager getUiManager(){
        return uiManager;
    }
    
    /**
     * Returns the EventProcessor registered with this GameStateManager
     * @see net.sf.jia.core.GameStateManager#getEventProcessor()
     */
    public EventProcessor getEventProcessor(){
        return eventProcessor;
    }
    
    /**
     * Returns the PlayerState
     * @see net.sf.jia.core.GameStateManager#getPlayerState()
     */
    public PlayerState getPlayerState(){
        return playerState;
    }
    
    /**
     * Method to call any time the game needs to respond to an action by the player.  If the
     * player moves to a square, or performs some other sort of action this method needs to
     * be called.
     * @see net.sf.jia.core.GameStateManager#notifyPlayerStateChanged()
     */
    public void notifyPlayerStateChanged(){
        if(GenericFlags.debugMessages) {
            log.debug("Notified of player state change.");
        }
        uiManager.notifyNeedUpdate();
        eventProcessor.processEvent(this, playerState.getCurrentModule().getSpace(playerState.getPosition()).getEvent());
        
        // TODO: Add a call to the event processor to check for events to process
    }
    
    /**
     * Returns an array of GameCharacters for this GameStateManager
     * @return
     */
    public GameCharacter[] getGameCharacters(){
        return new GameCharacter[0];
    }
    
    
}
